<script setup>
import { useCreate } from "../store/useCreate.js";
import { ref } from "vue";
import { ElMessage } from "element-plus";

const createStore = useCreate();

const tab = ref(1);
const verInfo = ref({});
const tabChange = (val) => {
  if (!createStore.openTrialVersion && val === 2) {
    return ElMessage.warning("当前未开启提供体验版开关");
  }
  tab.value = val;
  verInfo.value =
    tab.value === 1
      ? createStore.formData.standard
      : createStore.formData.experience;
};
tabChange(1);
</script>

<template>
  <div class="goods-select">
    <div class="tab">
      <span :class="{ active: tab === 1 }" @click="tabChange(1)">标准版</span>
      <span :class="{ active: tab === 2 }" @click="tabChange(2)">体验版</span>
    </div>
    <div class="goods-class">
      <p class="price"><span>¥</span>{{ verInfo.goodsAmount }}</p>
      <p class="tips">{{ verInfo.introduce }}</p>
      <p class="you-have">您将得到</p>
      <p
        class="goods-item"
        v-for="(item, index) of verInfo.deliver"
        :key="index"
      >
        <span class="r"></span>
        <span class="text">{{ item.content }}</span>
        <img src="@/assets/goods-select.png" alt="" />
      </p>
      <p class="deliver">
        <span class="deliver-1">交付周期</span>
        <span class="deliver-2">{{ verInfo.deliverDays }}天</span>
      </p>
      <p class="deliver">
        <span class="deliver-1">开启服务时间</span>
        <span class="deliver-2">48小时内</span>
      </p>
    </div>
    <div class="buy">
      <div class="buy-cut">
        <img src="@/assets/buy-cut.png" alt="" />
        <span>加入购物车</span>
      </div>
      <div class="to-service">
        <span>立即咨询</span>
        <img src="@/assets/show-service.png" alt="" />
      </div>
      <div class="but-now">立即购买</div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.goods-select {
  width: 430px;
  min-height: 550px;
  background: #ffffff;
  box-shadow: 0px 0px 16px 0px rgba(11, 13, 18, 0.06);
  border-radius: 16px 16px 16px 16px;
  border: 1px solid rgba(25, 30, 40, 0.08);
  margin-top: 16px;
  display: flex;
  flex-direction: column;
}
.tab {
  display: flex;
  span {
    font-weight: bold;
    cursor: pointer;
    flex: 1;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(25, 30, 40, 0.02);
    box-sizing: border-box;
    &:first-child {
      border-top-left-radius: 16px;
    }
    &:last-child {
      border-top-right-radius: 16px;
    }
    &.active {
      background: #ffffff;
      border-bottom: 2px solid rgba(29, 191, 115, 1);
      border-right: 1px solid #ededee;
    }
  }
}
.goods-class {
  flex: 1;
  margin: 20px 24px;
  box-sizing: border-box;
  border-bottom: 1px solid #ededee;
  .price {
    color: rgba(255, 79, 79, 1);
    font-size: 30px;
    font-weight: bold;
    margin-bottom: 6px;
    span {
      font-size: 20px;
    }
  }
  .tips {
    color: rgba(25, 30, 40, 0.6);
    margin-bottom: 20px;
  }
  .you-have {
    color: #191e28;
    font-weight: bold;
    font-size: 15px;
    margin-bottom: 8px;
  }
  .goods-item {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    .r {
      width: 4px;
      height: 4px;
      background: rgba(25, 30, 40, 0.1);
      border-radius: 100%;
      margin-right: 4px;
    }
    .text {
      flex: 1;
      color: #191e28;
    }
    img {
      width: 20px;
      height: 20px;
    }
  }
  .deliver {
    display: flex;
    align-items: center;
    margin-top: 16px;
    margin-bottom: 18px;
    color: #191e28;
    font-weight: bold;
    .deliver-1 {
      flex: 1;
    }
    .deliver-2 {
      color: #1dbf73;
    }
  }
}
.buy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px 24px;
  opacity: 0.4;
  .buy-cut {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: all 0.3s;
    &.active {
      span {
        color: rgba(29, 191, 115, 1);
      }
    }
    img {
      width: 24px;
      height: 24px;
      margin-bottom: 4px;
    }
    span {
      color: #191e28;
    }
  }
  .to-service {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px 8px 8px 8px;
    border: 1px solid #1dbf73;
    flex: 0 0 138px;
    height: 48px;
    cursor: pointer;
    user-select: none;
    span {
      color: #1dbf73;
      font-size: 16px;
      line-height: 16px;
      font-weight: bold;
      padding-right: 14px;
      margin-right: 14px;
      border-right: 1px solid rgba(232, 240, 236, 1);
    }
    img {
      width: 16px;
      height: 16px;
    }
  }
  .but-now {
    cursor: pointer;
    flex: 0 0 138px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1dbf73;
    border-radius: 8px 8px 8px 8px;
    font-size: 16px;
    color: #ffffff;
    font-weight: bold;
    user-select: none;
  }
}
.report {
  margin-top: 24px;
  text-align: right;
  cursor: pointer;
  a {
    color: rgba(25, 30, 40, 0.36);
    text-decoration: none;
  }
}
</style>